<?php

namespace Wonfu\Reflections;

use Doctrine\Common\Annotations\Annotation;

class MethodWrapper
{

    /**
     * @var Annotation;
     */
    private $annotation;

    /**
     * @var Annotation[]
     */
    private $annotations;

    /**
     * @var \ReflectionMethod
     */
    private $reflectionMethod;

    /**
     * @var Annotation
     */
    private $classAnnotation;


    /**
     * @param Annotation $annotation
     * @param \ReflectionMethod $reflectionMethod
     */
    public function __construct(Annotation $annotation, \ReflectionMethod $reflectionMethod)
    {
        $this->annotation = $annotation;
        $this->reflectionMethod = $reflectionMethod;
    }


    /**
     * @return Annotation
     */
    public function getAnnotation(): Annotation
    {
        return $this->annotation;
    }

    /**
     * @param Annotation $annotation
     */
    public function setAnnotation(Annotation $annotation): void
    {
        $this->annotation = $annotation;
    }

    /**
     * @return \ReflectionMethod
     */
    public function getReflectionMethod(): \ReflectionMethod
    {
        return $this->reflectionMethod;
    }

    /**
     * @param \ReflectionMethod $reflectionMethod
     */
    public function setReflectionMethod(\ReflectionMethod $reflectionMethod): void
    {
        $this->reflectionMethod = $reflectionMethod;
    }

    /**
     * @return Annotation|null
     */
    public function getClassAnnotation()
    {
        return $this->classAnnotation;
    }

    /**
     * @param Annotation|null $classAnnotation
     */
    public function setClassAnnotation($classAnnotation): void
    {
        $this->classAnnotation = $classAnnotation;
    }


    /**
     * @param $annotationClass
     * @return Annotation|null
     */
    public function getAnnotationWithName($annotationClass)
    {
        foreach ($this->annotations as $annotation) {
            if ($annotation instanceof $annotationClass) {
                return $annotation;
            }
        }
        return null;
    }

    /**
     * @return Annotation[]
     */
    public function getAnnotations(): array
    {
        return $this->annotations;
    }

    /**
     * @param object[] $annotations
     */
    public function setAnnotations(array $annotations): void
    {
        $this->annotations = $annotations;
    }


}